package cn.finder.httpcommons;

import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import cn.finder.httpcommons.utils.CommonUtils;
import cn.finder.httpcommons.utils.DateUtils;


public class ApiDictionary extends HashMap<String,String>{

	 /**
	 * 
	 */
	private static final long serialVersionUID = -2369709422009775921L;
	// Fields
    private final static String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

    // Methods
    public ApiDictionary()
    {
    }
    public ApiDictionary(HashMap<String, String> dictionary)
    {
    	super(dictionary);
    }

    public void add(String key, Object value)
    {
        String str=null;
        if (value == null)
        {
            str = null;
        }
        else if (value instanceof String)
        {
            str = (String)value;
        }
        else if (value instanceof Date)
        {
        	if(value!=null){
        		Date tmpValue = (Date)value;
        		str = DateUtils.formatDate(tmpValue);
        	}
            
        }
        else if (value instanceof Integer)
        {
        	int tmpValue =((Integer) value).intValue();
            str = tmpValue+"";
        }
        
        else if (value instanceof Long)
        {
        	long tmpValue =((Long) value).longValue();
            str = tmpValue+"";
        }
        
        else if (value instanceof Long)
        {
        	double tmpValue =((Double) value).doubleValue();
            str = tmpValue+"";
        }
        
        else if (value instanceof Boolean)
        {
        	boolean tmpValue =((Boolean) value).booleanValue();
            str = tmpValue+"";
        }
        
        else
        {
            str = value.toString();
        }
        this.put(key, str);

    }
    public void add(String key, String value)
    {
        if (!CommonUtils.isEmpty(key))
        {
            put(key, value);
        }

    }
    public void addAll(Map<String, String> dict)
    {
        if ((dict != null) && (dict.size() > 0))
        {
        	
          Set<Map.Entry<String, String>> setEntrys=	dict.entrySet();
          
          Iterator<Map.Entry<String, String>> itr = setEntrys.iterator();
          
          while(itr.hasNext()){
        	  
        	  java.util.Map.Entry<String, String> entry= itr.next();
        	  String key = entry.getKey();
        	  String value= entry.getValue();
        	  this.add(key, value);
          }
        	
        	
        }

    }
}
